import 'dart:async';

import 'package:bluetooth_protocols_parser_plugin_example/loading.dart';
import 'package:flutter/material.dart';

// 添加一个通用的错误处理函数
extension FutureErrorHandler<T> on Future<T> {
  Future<T> catchErrorHandler() {
    return catchError((err) {
      // 处理错误
      if (err is TimeoutException) {
        // 处理异常
        Loading.showToast(err.message ?? '');
        debugPrint("TimeoutException: ${err.message}");
      } else {
        // 处理异常
        Loading.showToast(err.toString());
        debugPrint("Exception: ${err.toString()}");
      }
    });
  }
}
